package com.lcy.lambda.stream;

import com.lcy.lambda.data.Author;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.lcy.lambda.data.Author.getAuthors;

/**
 * 创建流就三种方式：数组，集合，map
 * @author lcy
 * @date 2024/9/23 11:49
 */
public class 创建流 {
    public static void main(String[] args) {
        // 单列集合： 集合对象.stream()
        List<Author> authors = getAuthors();
        Stream<Author> stream = authors.stream();
        List<Author> collect = stream.collect(Collectors.toList());

        //数组：Arrays.stream(数组) 或者使用Stream.of来创建
        Integer[] arr = {1,2,3,4,5};
        Stream<Integer> arrayStream = Arrays.stream(arr);
        Stream<Integer> arrayStream2 = Stream.of(arr);

        //
        Map<String,Integer> map = new HashMap<>();
        map.put("蜡笔小新",19);
        map.put("黑子",17);
        map.put("日向翔阳",16);

        Stream<Map.Entry<String, Integer>> stream3 = map.entrySet().stream();
        Stream<String> stream4 = map.keySet().stream();

    }
}
